package com.wwwarehouse.contract.orders.import_order;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.custom_widget.time_pick.DateAndTimePickerDialog;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.DateUtils;
import com.wwwarehouse.common.tools.DialogTools;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.contract.bean.GetShopIdBean;
import com.wwwarehouse.contract.core.ContractConstant;
import com.wwwarehouse.contract.core.ImportOrdersSettingInfo;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;

import static contract.wwwarehouse.com.contract.R.drawable.import_orders_setting_normal;


/**
 * 订单导入设置详情
 * Created by ShineF on 2017/8/14 0014.
 */

public class ImportOrdersDetailsFragment extends BaseFragment implements View.OnClickListener, ElasticScrollView.OnPullListener {

    private LinearLayout mLlCard = null;
    private TextView mShopName = null;
    private TextView mSwitchText = null;
    private TextView mAuthTime = null;
    private ImageView mImgCB = null;
    private ImportOrdersSettingInfo data = null;
    private StateLayout mStateLayout;
    private String loadStartTime = null;
    private String loadEndTime = null;
    private Button mBtnSubmit = null;
    private ImageView mIvStartNA = null;
    private ImageView mIvStartCustom = null;
    private ImageView mIvEndNA = null;
    private ImageView mIvEndCustom = null;
    private TextView mTvStartNA = null;
    private TextView mTvStartCustom = null;
    private TextView mTvEndNA = null;
    private TextView mTvEndCustom = null;
    private TextView mTvStartSettingTime = null;
    private TextView mTvEndSettingTime = null;
    private TextView mTvStartTimeTitle = null;
    private TextView mTvEndTimeTitle = null;
    private RelativeLayout mRlStartTimeNA = null;
    private RelativeLayout mRlStartTimeCustom = null;
    private RelativeLayout mRlEndTimeCustom = null;
    private RelativeLayout mRlEndTimeNA = null;
    private ImageView mIvStartNext;
    private ImageView mIvEndNext;
    private String mStartTime = null;
    private String mEndTime = null;
    private long mShopId = 0;
    private boolean isShow = false;
    private int mType = 0;
    private ElasticScrollView mCustomScroll = null;
    private int mSubmitType = 0;
    private boolean mBooleanIsLoadSuccess = false;
    private int mStatus = -1;
    private String mDataEndTime = "2099-12-31 00:00";
    private String mDataEndTimeSec = "2099-12-31 00:00:00";
    private String mDataStartTime = "2000-01-01 00:00";
    private String mDataStartTimeSec = "2000-01-01 00:00:00";


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_import_orders_details, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mStateLayout = $(R.id.sl_state);
        mRlStartTimeNA = $(R.id.rl_start_time_na);
        mRlStartTimeCustom = $(R.id.rl_start_time_custom);
        mRlEndTimeCustom = $(R.id.rl_end_time_custom);
        mRlEndTimeNA = $(R.id.rl_end_time_na);
        mImgCB = $(R.id.iv_import_orders_checked);
        mBtnSubmit = $(R.id.btn_import_orders_submit);
        mAuthTime = $(R.id.tv_import_orders_details_time);
        mShopName = $(R.id.tv_import_orders_details_name);
        mSwitchText = $(R.id.tv_import_orders_details_check);
        mLlCard = $(R.id.ll_card);
        mIvStartNA = $(R.id.ib_start_na);
        mIvStartCustom = $(R.id.ib_start_custom);
        mIvEndNA = $(R.id.ib_end_na);
        mIvEndCustom = $(R.id.ib_end_custom);
        mTvStartNA = $(R.id.tv_start_time_na);
        mTvStartCustom = $(R.id.tv_start_time_custom);
        mTvEndNA = $(R.id.tv_end_time_na);
        mTvEndCustom = $(R.id.tv_end_time_custom);
        mTvStartSettingTime = $(R.id.tv_start_setting_number);
        mTvEndSettingTime = $(R.id.tv_end_setting_number);
        mTvStartTimeTitle = $(R.id.tv_start_time_title);
        mTvEndTimeTitle = $(R.id.tv_end_time_title);
        mIvStartNext = $(R.id.iv_start_next);
        mIvEndNext = $(R.id.iv_end_next);
        mCustomScroll = $(R.id.custom_scroll_view);
        mLlCard.setVisibility(View.INVISIBLE);
        mBtnSubmit.setEnabled(false);
        mBtnSubmit.setSelected(false);
        mImgCB.setOnClickListener(this);
        mBtnSubmit.setOnClickListener(this);
        mRlStartTimeNA.setOnClickListener(this);
        mRlStartTimeCustom.setOnClickListener(this);
        mRlEndTimeCustom.setOnClickListener(this);
        mRlEndTimeNA.setOnClickListener(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        ((BaseCardDeskActivity) mActivity).hideTitleBt();
        isShow = !isShow;
    }


    @Override
    public void setTitle() {
        if (peekFragment() instanceof ImportOrdersDetailsFragment) {
            mActivity.setTitle(R.string.import_orders);
        }
    }

    @Override
    public void requestDatas() {
        Bundle bundle = getArguments();
        if (null != bundle) {
            GetShopIdBean.ListBean mBean = bundle.getParcelable("data");
            mType = bundle.getInt("type");
            mStatus = bundle.getInt("status");
            if (null != mBean) {
                if (null != mBean.getShopName())
                    mShopName.setText(mBean.getShopName());
                mShopId = mBean.getShopId();
            }
        }
        mStateLayout.showProgressView(true);
        Map<String, Object> map = new HashMap<>();
//        map.put("shopId", "251901");
        map.put("shopId", mShopId);
        loadData(ContractConstant.GET_IMPORT_ORDERS_INFO, map, 1);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.iv_import_orders_checked) {
            if (mImgCB.isSelected()) {
                setSwitchBtn(0);
            } else {
                setSwitchBtn(1);
            }
        } else if (i == R.id.btn_import_orders_submit) {
            if (!mImgCB.isSelected()) {
                DialogTools.getInstance().showCustomDialogPrompt(mActivity, null
                        , getString(R.string.import_orders_dialog), true, new DialogTools.ConfirmListener() {
                            @Override
                            public void setConfirmListener(Dialog dialog, View view, String input) {
                                submitEdit();
                                dialog.dismiss();
                            }
                        });
            } else {
                if (1 == DateUtils.compareDate(mEndTime, mStartTime))
                    submitEdit();
                else
                    ToastUtils.showToast("结束时间不能小于开始时间");
            }
        } else if (i == R.id.rl_start_time_na) {
            mStartTime = mDataStartTime;
            setStartTimeStatus(1);
        } else if (i == R.id.rl_start_time_custom) {
            setStartTime();
        } else if (i == R.id.rl_end_time_na) {
            mEndTime = mDataEndTime;
            setEndTimeStatus(1);
        } else if (i == R.id.rl_end_time_custom) {
            setEndTime();
        }
    }


    public void submitEdit() {
        Map<String, Object> map = new HashMap<>();
        if (mIvEndNA.isSelected()) {
            map.put("importEndTime", mDataEndTimeSec);
        }
        if (mIvEndCustom.isSelected()) {
            map.put("importEndTime", mEndTime + ":00");
        }
        if (mIvStartNA.isSelected()) {
            map.put("importStartTime", mDataStartTimeSec);
        }
        if (mIvStartCustom.isSelected()) {
            map.put("importStartTime", mStartTime + ":00");
        }
        map.put("shopId", mShopId);
        if (mImgCB.isSelected()) {
            map.put("tradeDown", "1");
        } else {
            map.put("tradeDown", "0");
        }
        map.put("userId", "123456");
        loadData(ContractConstant.EDIT_IMPORT_ORDERS_INFO, map, 2);
    }

    public void loadData(String url, final Map<String, Object> map, int what) {
        NoHttpUtils.httpPost(url, map, new NoHttpUtils.OnResponseListener() {
            @Override
            public void onSucceed(CommonClass commonClass, int what) {
                switch (what) {
                    case 1:
                        switch (commonClass.getCode()) {
                            case "0":
                                mBooleanIsLoadSuccess = true;
                                data = JSON.parseObject(commonClass.getData().toString(), ImportOrdersSettingInfo.class);
                                setData();
                                break;
                            default:
                                mBooleanIsLoadSuccess = false;
                                mStateLayout.showNetworkView(true);
                                mStateLayout.setNetworkListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Map<String, Object> map = new HashMap<>();
                                        map.put("shopId", mShopId);
                                        loadData(ContractConstant.GET_IMPORT_ORDERS_INFO, map, 1);
                                    }
                                });
                                break;
                        }
                        break;
                    case 2:
                        switch (commonClass.getCode()) {
                            case "0":
                                /*
                                  type = 1 订单是关闭状态
                                  type = 2 开始时间和结束时间都是不限定时间
                                  type = 3 开始时间和结束时间都是自定义时间
                                  type = 4 结束时间是不限定时间, 开始时间是自定义时间
                                  type = 5 结束时间是自定义时间, 开始时间不限定时间
                                 */
                                if (!map.containsKey("importEndTime") && !map.containsKey("importStartTime")) {
                                    mSubmitType = 1;
                                } else if (map.get("importEndTime").equals(mDataEndTimeSec) && map.get("importStartTime").equals(mDataStartTimeSec)) {
                                    mSubmitType = 2;
                                } else if (!map.get("importEndTime").equals(mDataEndTimeSec) && !map.get("importStartTime").equals(mDataStartTimeSec)) {
                                    mSubmitType = 3;
                                } else if (map.get("importEndTime").equals(mDataEndTimeSec) && !map.get("importStartTime").equals(mDataStartTimeSec)) {
                                    mSubmitType = 4;
                                } else if (!map.get("importEndTime").equals(mDataEndTimeSec) && map.get("importStartTime").equals(mDataStartTimeSec)) {
                                    mSubmitType = 5;
                                }
                                ImportOrdersDetailsSubmitFragment fragment = new ImportOrdersDetailsSubmitFragment();
                                Bundle bundle = new Bundle();
                                bundle.putString("startTime", mStartTime);
                                bundle.putString("endTime", mEndTime);
                                bundle.putInt("submitType", mSubmitType);
                                bundle.putInt("status", mStatus);
                                fragment.setArguments(bundle);
                                pushFragment(fragment);
                                break;
                            default:
                                ToastUtils.showToast(commonClass.getMsg());
                                break;
                        }
                        break;
                }
            }

            @Override
            public void onFailed(String result, int what) {

            }

            @Override
            public void onFinish(int what) {

            }
        }, what);
    }

    public void setData() {
        if (data != null) {
            mStartTime = data.getImportStartTime();
            mEndTime = data.getImportEndTime();
            int mTradeDown = data.getTradeDown();
            if (mStartTime != null) {
                mStartTime = mStartTime.substring(0, 16);
            }
            if (mEndTime != null) {
                mEndTime = mEndTime.substring(0, 16);
            }
            if (data.getAuthTime() != null) {
                mAuthTime.setText(getString(R.string.auth_text) + data.getAuthTime().substring(0, 10));
            }
            setSwitchBtn(data.getTradeDown());
            if (mTradeDown == 1) {
                if (mDataStartTime.equals(mStartTime)) {
                    setStartTimeStatus(1);
                    mStartTime = mDataStartTime;
                } else if (null != mStartTime) {
                    setStartTimeStatus(2);
                }
                if (mDataEndTime.equals(mEndTime)) {
                    setEndTimeStatus(1);
                } else if (null != mEndTime) {
                    setEndTimeStatus(2);
                }
            } else if (mTradeDown == 0) {
                if (mDataStartTime.equals(mStartTime)) {
                    setStartTimeStatus(4);
                } else if (null != mStartTime) {
                    setStartTimeStatus(5);
                } else {
                    setStartTimeStatus(6);
                }
                if (mDataEndTime.equals(mEndTime)) {
                    setEndTimeStatus(4);
                } else if (null != mEndTime) {
                    setEndTimeStatus(5);
                } else {
                    setEndTimeStatus(6);
                }
            }
            if (mType == 1) {
                mCustomScroll.setOnPullListener(this);
            }
            mStateLayout.showContentView();
            mLlCard.setVisibility(View.VISIBLE);
            if (mStatus == 0) {
                mBtnSubmit.setSelected(false);
                mBtnSubmit.setEnabled(false);
            }
        }
//        ((BaseCardDeskActivity) mActivity).setOnBackListener(new BaseActivity.OnBackListener() {
//            @Override
//            public boolean onBack() {
//                if (mBooleanIsLoadSuccess && peekFragment() instanceof ImportOrdersDetailsFragment) {
//                    DialogTools.getInstance().showCustomDialogPrompt(mActivity, null
//                            , getString(R.string.import_orders_cancel), true, new DialogTools.ConfirmListener() {
//                                @Override
//                                public void setConfirmListener(Dialog dialog, View view, String input) {
//                                    mBooleanIsLoadSuccess = false;
//                                    dialog.dismiss();
//                                    popFragment();
//                                }
//                            }, "确定返回", "暂时不返回");
//                    return true;
//                } else {
//                    return false;
//                }
//            }
//        });
    }


    /**
     * 设置开始时间
     */
    public void setStartTime() {
        new DateAndTimePickerDialog.Builder(mActivity)
                .setData(loadStartTime)
                .setTitle(getResources().getString(R.string.start_time))
                .setOnDateSelectedListener(new DateAndTimePickerDialog.OnDateTimeSelectedListener() {
                    @Override
                    public void onDateTimeSelected(String date) {

                        if (null != mEndTime && !"2099-12-31 00:00:00".equals(mEndTime)) {
                            if (1 == DateUtils.compareDate(date, mEndTime)) {
                                ToastUtils.showToast(getString(R.string.set_end_time_info));
                                return;
                            }
                        }
                        if (1 == DateUtils.compareDate(getSystemDate(), date)) {
                            ToastUtils.showToast(R.string.set_start_time_info);
                            if (mStartTime == null) {
                                setStartTimeStatus(3);
                            } else if (mStartTime.equals(mDataStartTime)) {
                                setStartTimeStatus(1);
                            } else {
                                setStartTimeStatus(2);
                            }
                            return;
                        }
                        mStartTime = date;
                        setStartTimeStatus(2);
                    }

                    @Override
                    public void onCancel() {

                    }
                })
                .create()
                .show();
    }

    /**
     * 设置结束时间
     */
    public void setEndTime() {
        new DateAndTimePickerDialog.Builder(mActivity)
                .setData(loadEndTime)
                .setTitle(getResources().getString(R.string.end_time))
                .setOnDateSelectedListener(new DateAndTimePickerDialog.OnDateTimeSelectedListener() {
                    @Override
                    public void onDateTimeSelected(String date) {
                        if (null != mStartTime && !"2000-01-01 00:00:00".equals(mStartTime)) {
                            if (1 == DateUtils.compareDate(mStartTime, date)) {
                                if (mEndTime == null) {
                                    setEndTimeStatus(3);
                                } else if (mEndTime.equals(mDataEndTime)) {
                                    setEndTimeStatus(1);
                                } else {
                                    setEndTimeStatus(2);
                                }
                                ToastUtils.showToast(getString(R.string.set_end_time_info));
                                return;
                            }
                        }
                        mEndTime = date;
                        setEndTimeStatus(2);
                    }

                    @Override
                    public void onCancel() {

                    }
                })
                .create()
                .show();

    }


    @Override
    public void onDownPull() {
        if (!isShow) {
            ((BaseCardDeskActivity) mActivity).showTitleBt1();
            ((BaseCardDeskActivity) mActivity).setTitleBt1Text(R.string.edit_import_orders);
//            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams
//                    (LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//            params.setMargins(0, ConvertUtils.dip2px(mActivity, 5), ConvertUtils.dip2px(mActivity, 15), 0);
//            titleBt1.setLayoutParams(params);
        } else {
            ((BaseCardDeskActivity) mActivity).hideTitleBt();
        }
        isShow = !isShow;
    }

    @Override
    public void titleBt1Click() {
        super.titleBt1Click();
        popFragment();
        ((BaseCardDeskActivity) mActivity).hideTitleBt();
        isShow = !isShow;
    }

    @Override
    public void onUpPull() {

    }

    /**
     * 设置导入开关状态
     *
     * @param what 状态
     */
    public void setSwitchBtn(int what) {
        if (0 == what) {
            mImgCB.setSelected(false);
            mSwitchText.setText(R.string.import_close);
            if (mStartTime != null) {
                if (mStartTime.equals(mDataStartTime)) {
                    setStartTimeStatus(4);
                } else {
                    setStartTimeStatus(5);
                }
            } else {
                setStartTimeStatus(6);
            }
            if (null != mEndTime) {
                if (mEndTime.equals(mDataEndTime)) {
                    setEndTimeStatus(4);
                } else {
                    setEndTimeStatus(5);
                }
            } else {
                setEndTimeStatus(6);
            }
            mTvEndTimeTitle.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mTvStartTimeTitle.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mIvStartNext.setBackground(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_close));
            mIvEndNext.setBackground(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_close));
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(false);
            mIvEndNA.setSelected(false);
            mIvEndCustom.setSelected(false);
            mRlStartTimeNA.setEnabled(false);
            mRlStartTimeCustom.setEnabled(false);
            mRlEndTimeNA.setEnabled(false);
            mRlEndTimeCustom.setEnabled(false);
        } else if (1 == what) {
            mImgCB.setSelected(true);
            mSwitchText.setText(R.string.import_open);
            mTvStartTimeTitle.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c7_96999e));
            mTvEndTimeTitle.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c7_96999e));
            mIvEndNext.setBackground(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_pargers_time_next));
            mIvStartNext.setBackground(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_pargers_time_next));
            mRlStartTimeNA.setEnabled(true);
            mRlStartTimeCustom.setEnabled(true);
            mRlEndTimeNA.setEnabled(true);
            mRlEndTimeCustom.setEnabled(true);
            if (mStartTime != null) {
                if (mDataStartTime.equals(mStartTime)) {
                    setStartTimeStatus(1);
                } else {
                    setStartTimeStatus(2);
                }
            } else {
                setStartTimeStatus(3);
            }
            if (mEndTime != null) {
                if (mDataEndTime.equals(mEndTime)) {
                    setEndTimeStatus(1);
                } else {
                    setEndTimeStatus(2);
                }
            } else {
                setEndTimeStatus(3);
            }
        }
        mBtnSubmit.setEnabled(getStatus());
        mBtnSubmit.setSelected(getStatus());
    }

    /**
     * 设置开始时间状态
     * <p>
     * 1:不限时间选中
     * 2:自定义时间选中
     * 3:开关开启->都不选中
     * 4:开关关闭->不限时间选中
     * 5:开关关闭->自定义时间选中
     * 6:开关关闭->都不选中
     *
     * @param what 状态码
     */
    public void setStartTimeStatus(int what) {
        if (1 == what) {
            mIvStartNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartNA.setSelected(true);
            mIvStartCustom.setSelected(false);
            mTvStartNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c1_337cff));
            mTvStartCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvStartSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c7_96999e));
            if (null != mStartTime && mStartTime.equals(mDataStartTime)) {
                mTvStartSettingTime.setText(getString(R.string.edit_start_time));
            } else {
                mTvStartSettingTime.setText(mStartTime);
            }
        } else if (2 == what) {
            mIvStartNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(true);
            mTvStartCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c1_337cff));
            mTvStartNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvStartSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c1_337cff));
            if (null == mStartTime || mStartTime.equals(mDataStartTime)) {
                mTvStartSettingTime.setText(getString(R.string.edit_start_time));
            } else {
                mTvStartSettingTime.setText(mStartTime);
            }

        } else if (3 == what) {
            mIvStartNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(false);
            mTvStartCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvStartSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c7_96999e));
            mTvStartNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            if (mStartTime == null || mStartTime.equals(mDataStartTime)) {
                mTvStartSettingTime.setText(getString(R.string.edit_start_time));
            } else {
                mTvStartSettingTime.setText(mStartTime);
            }
        } else if (4 == what) {
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(false);
            mTvStartCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvStartSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvStartNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mIvStartNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvStartCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, import_orders_setting_normal));
            if (null != mStartTime && mStartTime.equals(mDataStartTime)) {
                mTvStartSettingTime.setText(getString(R.string.edit_start_time));
            } else {
                mTvStartSettingTime.setText(mStartTime);
            }
        } else if (5 == what) {
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(false);
            mTvStartCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mTvStartSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mTvStartNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mIvStartNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_normal));
            mIvStartCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            if (null != mStartTime && mStartTime.equals(mDataStartTime)) {
                mTvStartSettingTime.setText(getString(R.string.edit_start_time));
            } else {
                mTvStartSettingTime.setText(mStartTime);
            }
        } else if (6 == what) {
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(false);
            mTvStartCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvStartSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvStartNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mIvStartNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_normal));
            mIvStartCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_normal));
        }
        mBtnSubmit.setEnabled(getStatus());
        mBtnSubmit.setSelected(getStatus());
    }

    /**
     * 设置结束时间状态
     * <p>
     * 1:不限时间选中
     * 2:自定义时间选中
     * 3:开关开启->都不选中
     * 4:开关关闭->不限时间选中
     * 5:开关关闭->自定义时间选中
     * 6:开关关闭->都不选中
     *
     * @param what 状态码
     */
    public void setEndTimeStatus(int what) {
        if (1 == what) {
            mIvEndCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndNA.setSelected(true);
            mIvEndCustom.setSelected(false);
            mTvEndNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c1_337cff));
            mTvEndCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvEndSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c7_96999e));
            if (null != mEndTime && mEndTime.equals(mDataEndTime)) {
                mTvEndSettingTime.setText(getString(R.string.edit_end_time));
            } else {
                mTvEndSettingTime.setText(mEndTime);
            }
        } else if (2 == what) {
            mIvEndCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndNA.setSelected(false);
            mIvEndCustom.setSelected(true);
            mTvEndCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c1_337cff));
            mTvEndNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvEndSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c1_337cff));
            if (null != mEndTime && mEndTime.equals(mDataEndTime)) {
                mTvEndSettingTime.setText(getString(R.string.edit_end_time));
            } else {
                mTvEndSettingTime.setText(mEndTime);
            }
        } else if (3 == what) {
            mIvEndCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndNA.setSelected(false);
            mIvEndCustom.setSelected(false);
            mTvEndNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvEndCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c4_121417));
            mTvEndSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c7_96999e));
            if (null == mEndTime || mEndTime.equals(mDataEndTime)) {
                mTvEndSettingTime.setText(getString(R.string.edit_end_time));
            } else {
                mTvEndSettingTime.setText(mEndTime);
            }
        } else if (4 == what) {
            mIvStartNA.setSelected(false);
            mIvStartCustom.setSelected(false);
            mTvEndCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvEndSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvEndNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mIvEndNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            mIvEndCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, import_orders_setting_normal));
            if (null != mEndTime && mEndTime.equals(mDataEndTime)) {
                mTvEndSettingTime.setText(getString(R.string.edit_end_time));
            } else {
                mTvEndSettingTime.setText(mEndTime);
            }
        } else if (5 == what) {
            mIvEndNA.setSelected(false);
            mIvEndCustom.setSelected(false);
            mTvEndCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mTvEndSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c8_d5d7dc));
            mTvEndNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mIvEndNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_normal));
            mIvEndCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.selector_radio_button_img));
            if (null != mEndTime && mEndTime.equals(mDataEndTime)) {
                mTvEndSettingTime.setText(getString(R.string.edit_end_time));
            } else {
                mTvEndSettingTime.setText(mEndTime);
            }
        } else if (6 == what) {
            mIvEndNA.setSelected(false);
            mIvEndCustom.setSelected(false);
            mTvEndCustom.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvEndSettingTime.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mTvEndNA.setTextColor(ContextCompat.getColor(mActivity, R.color.common_color_c9_e8e9eb));
            mIvEndNA.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_normal));
            mIvEndCustom.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.import_orders_setting_normal));
        }
        mBtnSubmit.setEnabled(getStatus());
        mBtnSubmit.setSelected(getStatus());
    }

    /**
     * 获取按钮是否可点击
     *
     * @return 是否可点击
     */
    public boolean getStatus() {
        return (mIvStartNA.isSelected() || mIvStartCustom.isSelected())
                && (mIvEndNA.isSelected() || mIvEndCustom.isSelected())
                || !mImgCB.isSelected();
    }

    public String getSystemDate() {
        SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        return sDateFormat.format(new java.util.Date());
    }
}
